package com.woniuxy.vechicle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.vechicle.pojo.Vehicle;
import com.woniuxy.vechicle.service.VehicleService;
import com.woniuxy.vechicle.mapper.VehicleMapper;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;

/**
* @author yolo
* @description 针对表【vehicle(车辆表)】的数据库操作Service实现
* @createDate 2025-07-14 17:51:44
*/
@Service
@Slf4j
public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle>
    implements VehicleService {

    @Override
    public Vehicle getByPlateNumber(String plateNumber) {
        log.info("开始查询车辆信息，车牌号: {}", plateNumber);
        
        try {
            LambdaQueryWrapper<Vehicle> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Vehicle::getPlateNumber, plateNumber);
            
            // 打印生成的SQL语句
            log.info("查询条件: plateNumber = {}", plateNumber);
            
            Vehicle vehicle = getOne(queryWrapper);
            
            if (vehicle != null) {
                log.info("查询到车辆信息: id={}, plateNumber={}, status={}, ownerId={}, plateType={}", 
                    vehicle.getId(), vehicle.getPlateNumber(), vehicle.getStatus(), 
                    vehicle.getOwnerId(), vehicle.getPlateType());
            } else {
                log.warn("未查询到车辆信息，车牌号: {}", plateNumber);
            }
            
            return vehicle;
        } catch (Exception e) {
            log.error("查询车辆信息时发生错误，车牌号: " + plateNumber, e);
            throw e;
        }
    }
} 